const https = require('https')
const cheerio = require('cheerio')
const fs = require('fs')


let html = ''
let content = ''
https.get('https://my.oschina.net/u/4090830/blog/11407609', (res) => {

    res.on('data', chunk => {
        html+=chunk
    })

    res.on('end', () => {
        const $ = cheerio.load(html)
        let s = $('.article-detail .content div').text();
        let s1 = s.replace(/\n/g, '')
        console.log(s1)
        content = {content: s1}

        fs.writeFile('./oschina.json', JSON.stringify(content), (err) => {
            if(err) {
                throw err
            }
            console.log('文件保存成功')
        })
    })
})